[#ftl]
[#include "commonDef.ftl" /]
${pack_own}

import java.util.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.github.pagehelper.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

${base_pack}.common.utils.PageUtils;
${base_pack}.common.utils.MessageUtils;
${base_pack}.common.utils.SecurityUtils;
${base_pack}.common.utils.bean.BeanUtils;
${base_pack}.common.exception.ServiceException;
${base_pack}.common.core.page.TableDataInfo;
${base_pack}.common.core.BaseManagerUtils;
${import_method_class}[#-- 方法对象引入 --]
${import_table_class}[#-- 表对象引入 --]
${import_class}
${pack_service}

/**
 * ${data_main.moduleKeyName}
 * @author ${author_str!"zhouliang"}
 * @date ${date_str}
 */
@Service("${lname_service}")
public class ${name_own} implements ${name_service} {
[#if resource_table_class??]
${resource_table_class}[#-- 载入类 --]
[/#if]
[#if resource_class??]
${resource_class}[#-- 载入类 --]
[/#if]
    
[#if data_method??]
[#list data_method as mdx]
[#if mdx.needFlag == '1']
    /**
     * ${mdx.methodKeyName}
     */
    [#if mdx.methodOprType == 'getpage' ]
    @Override
    public TableDataInfo<${mdx.tags['name_res']}> get${ServiceMethodName(data_main,mdx)}(${mdx.tags['name_req']} reqData) throws Exception{
        [#if data_table?? && data_table?size>1][#assign tblx='null'  sqlx='null'/]
        [#list mdx.orderEntitys["res"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0 && map_table[eVO.useTableCode]??]
        [#assign tblx=map_table[eVO.useTableCode]  sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] /][#break]
        [/#if]
        [/#list]
        [#assign pmkey="pageParamMap" /]
        [#if tblx=='null']
        [#assign tblx = data_table[0]  sqlx=tblx.sqlInterfacesMap['pageList'] /]
        [/#if]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        Page<Object> pageHP = PageUtils.startPage();//分页，紧跟SQL
        List<${tblx.tags['name_entityVo']}> list = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        List<${mdx.tags['name_res']}> resDTO=BeanUtils.copyToList(list, ${mdx.tags['name_res']}.class);
        [#elseif data_table?? && data_table?size>0]
        [#assign tblx = data_table[0]  sqlx=tblx.sqlInterfacesMap['pageList'] pmkey="pageParamMap" /]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        Page<Object> pageHP = PageUtils.startPage();//分页，紧跟SQL
        List<${tblx.tags['name_entityVo']}> list = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        List<${mdx.tags['name_res']}> resDTO=BeanUtils.copyToList(list, ${mdx.tags['name_res']}.class);
        [/#if]
        
        return BaseManagerUtils.getDataTable(resDTO, pageHP.getTotal());;
    }
    [#elseif mdx.methodOprType == 'getdetail' ]
    @Override
    public ${mdx.tags['name_res']} get${ServiceMethodName(data_main,mdx)}(${mdx.tags['name_req']} reqData) throws Exception{
        ${mdx.tags['name_res']} resDTO = new ${mdx.tags['name_res']}();
        [#if data_table?? && data_table?size>1]
        [#list  mdx.orderEntitys["res"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "1"][#-- 非对象和对象互斥，1和2,3不共存--]
        [#assign tblx = map_table[eVO.useTableCode]  sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] rdkey=tblx.tableJavaCode+'Record'
          pmkey=tblx.tableJavaCode+'ParamMap'  /]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        ${tblx.tags['name_entity']} ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        if(${rdkey} == null){
            throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        BeanUtils.copyProperties(${rdkey}, resDTO);
        [#break]
        [/#if]
        [/#list]
        [#list mdx.orderEntitys["res"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "2"][#-- 非对象和对象互斥，2,3共存--]
        [#assign tblx = map_table[eVO.useTableCode]  sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] rdkey=tblx.tableJavaCode+'Record'
          pmkey=tblx.tableJavaCode+'ParamMap' /]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        ${tblx.tags['name_entity']} ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        resDTO.set${eVO.fieldJavaCode?cap_first}(BeanUtils.copyProperties(${rdkey}, ${eVO.javaType}.class));
        [/#if]
        [/#list]
        [#list mdx.orderEntitys["res"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "3"][#-- 非对象和对象互斥，2,3共存--]
        [#assign tblx = map_table[eVO.useTableCode]  sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode]  rdkey=tblx.tableJavaCode+'Records'
         dtkey1=eVO.fieldJavaCode?uncap_first+'List' pmkey=tblx.tableJavaCode+'ParamMap' /]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        List<${tblx.tags['name_entity']}> ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        if(${rdkey} !=null && ${rdkey}.size()>0){
            List<${eVO.javaType}> ${dtkey1} = new ArrayList<>();
            for(${tblx.tags['name_entity']} x : ${rdkey}){
                ${dtkey1}.add(BeanUtils.copyProperties(x, ${eVO.javaType}.class));
            }
            resDTO.set${eVO.fieldJavaCode?cap_first}(${dtkey1});
        }
        [/#if]
        [/#list]
        
        [#elseif data_table?? && data_table?size>0]
        [#assign tblx = data_table[0]  sqlx=tblx.sqlInterfacesMap['selectOne'] rdkey=tblx.tableJavaCode+'Record' pmkey=tblx.tableJavaCode+'ParamMap'/]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        ${tblx.tags['name_entity']} ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        if(${rdkey} == null){
            throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        BeanUtils.copyProperties(${rdkey}, resDTO);
        
        [/#if]
        return resDTO;
    }
    [#elseif mdx.methodOprType == 'doadd' ]
    @Override
    public ${mdx.tags['name_res']} do${ServiceMethodName(data_main,mdx)}(${mdx.tags['name_req']} reqData) throws Exception{
        ${mdx.tags['name_res']} resDTO = new ${mdx.tags['name_res']}();
        Date time = BaseManagerUtils.getSystemTime().getDate();
        [#if data_table?? && data_table?size>1]
        [#assign eList = mdx.orderEntitys["req"]![] /]
        [#list eList as eVO]
        [#if eVO.useTableCode?trim?length>0]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] /]
        [#if tblx.primaryEntity?? && tblx.primaryEntity?size>0]
        [#if eVO.fieldType == "1" || eVO.fieldType == "2"]
        [#list tblx.primaryEntity as b]
        ${b.javaType} ${b.columnJavaCode} = null;
        [/#list]
        [#elseif eVO.fieldType == "3" ]
        [#list tblx.primaryEntity as b]
        Map<${b.javaType},${b.javaType}> ${b.columnJavaCode}Maps = new HashMap<>();
        [/#list]
        [/#if]
        [/#if]
        [/#if]
        [/#list]
        
        
        [#list eList as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "1"]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] dtkey='reqData' rdkey=tblx.tableJavaCode?uncap_first+'Record' /]
        [@doaddForInsert mdx=mdx tblx=tblx sqlx=sqlx blankflag='' dtkey=dtkey rdkey=rdkey ftype='1' currentitys=eList /]
        
        [/#if]
        [/#list]
        [#list eList as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "2"]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] dtkey='reqData.get'+eVO.fieldJavaCode?cap_first+'()' rdkey=tblx.tableJavaCode?uncap_first+'Record' /]
        [@doaddForInsert mdx=mdx tblx=tblx sqlx=sqlx blankflag='' dtkey=dtkey rdkey=rdkey ftype='1' currentitys=eVO.children![]  /]
        
        [/#if]
        [/#list]
        [#list eList as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "3" ]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] dtkey1=eVO.fieldJavaCode +'List' dtkey=eVO.fieldJavaCode +'x' rdkey=tblx.tableJavaCode?uncap_first+'Record'/]
        List<${eVO.javaType}> ${dtkey1} = ${'reqData.get'+eVO.fieldJavaCode?cap_first+'()'};
        if(${dtkey1} != null && ${dtkey1}.size()>0){
            for(${eVO.javaType} ${dtkey} : ${dtkey1}){
                [@doaddForInsert mdx=mdx tblx=tblx sqlx=sqlx blankflag='        ' dtkey=dtkey rdkey=rdkey ftype='2' currentitys=eVO.children![] /]
            }
        }
        
        [/#if]
        [/#list]
        [#assign eList = mdx.orderEntitys["res"]![] /]
        [#list eList as eVO]
        [#if eVO.useTableCode?trim?length>0]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] dtkey='resDTO' 
        rdkey=tblx.tableJavaCode?uncap_first+'Record' pmkey=tblx.tableJavaCode+'ParamMap' /]
        [#if tblx.primaryEntity?size>0]
        [@doeditForSelect tblx=tblx sqlx=sqlx dtkey=dtkey rdkey=rdkey pmkey=pmkey existflag=false /]
        [/#if]
        [/#if]
        [/#list]
        
        [#elseif data_table?? && data_table?size>0]
        [#assign tblx=data_table[0] sqlx=tblx.sqlInterfacesMap["insert"] dtkey='reqData' rdkey=tblx.tableJavaCode?uncap_first+'Record' /]
        [#list tblx.primaryEntity as b]
        ${b.javaType} ${b.columnJavaCode} = null;
        [/#list]
        [@doaddForInsert mdx=mdx tblx=tblx sqlx=sqlx blankflag='' dtkey=dtkey rdkey=rdkey ftype='1' currentitys=mdx.orderEntitys["req"]![] /]
        
        [#assign tblx=data_table[0] sqlx=tblx.sqlInterfacesMap["selectOne"] dtkey='resDTO' rdkey=tblx.tableJavaCode?uncap_first+'Record'
          pmkey=tblx.tableJavaCode+'ParamMap' /]
        [#if tblx.primaryEntity?size>0]
        [@doeditForSelect tblx=tblx sqlx=sqlx dtkey=dtkey rdkey=rdkey  pmkey=pmkey existflag=false/]
        [/#if]
        
        [/#if]
        return resDTO;
    }
    [#elseif mdx.methodOprType == 'doedit' || (mdx.methodOprType == 'dodelete' && mdx.fieldEx['businessType']!"UPDATE"=="UPDATE")]
    @Override
    public ${mdx.tags['name_res']} do${ServiceMethodName(data_main,mdx)}(${mdx.tags['name_req']} reqData) throws Exception{
        ${mdx.tags['name_res']} resDTO = new ${mdx.tags['name_res']}();
        Date time = BaseManagerUtils.getSystemTime().getDate();
        
        [#if data_table?? && data_table?size>1][#assign currtable = "" /]
        [#list mdx.orderEntitys["req"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] /]
        [#if tblx.primaryEntity?? && tblx.primaryEntity?size>0]
        [#if eVO.fieldType == "1"][#if currtable == ""][#assign currtable=tblx.tableCode /][/#if]
        [#list tblx.primaryEntity as b]
        ${b.javaType} ${b.columnJavaCode} = ${'reqData.get'+b.columnJavaCode?cap_first+'()'};
        [/#list]
        [#elseif eVO.fieldType == "2"][#if currtable == ""][#assign currtable=tblx.tableCode /][/#if]
        [#list tblx.primaryEntity as b]
        ${b.javaType} ${b.columnJavaCode} = ${'reqData.get'+eVO.fieldJavaCode?cap_first+'().get'+b.columnJavaCode?cap_first+'()'};
        [/#list]
        [#elseif eVO.fieldType == "3"]
        [#list tblx.primaryEntity as b]
        Map<${b.javaType}, ${b.javaType}> ${b.columnJavaCode}Maps = new HashMap<>();
        [/#list]
        [/#if]
        [/#if]
        [/#if]
        [/#list]
        [#list mdx.orderEntitys["res"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0]
        [#assign tblx = map_table[eVO.useTableCode]  sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] rdkey=tblx.tableJavaCode+'Data'
          pmkey=tblx.tableJavaCode+'ParamMap' /]
        [#if currtable==tblx.tableCode && tblx.primaryEntity?size>0]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        ${tblx.tags['name_entity']} ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        if(${rdkey} == null){
            throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        [/#if]
        [/#if]
        [/#list]
        
        [#list mdx.orderEntitys["req"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "1"]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] dtkey='reqData' rdkey=tblx.tableJavaCode?uncap_first+'Record'
          currtableflag=(currtable==tblx.tableCode) pmkey=tblx.tableJavaCode+'ParamMap'/]
        [@doeditForUpdate tblx=tblx  sqlx=sqlx  dtkey=dtkey  rdkey=rdkey pmkey=pmkey ftype='1' blankflag='' currentitys=mdx.orderEntitys["req"]![] currtableflag=currtableflag/]
        [/#if]
        [/#list]
        [#list mdx.orderEntitys["req"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "2"]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] dtkey='reqData.get'+eVO.fieldJavaCode?cap_first+'()' 
        rdkey=eVO.fieldJavaCode?uncap_first+'Record' currtableflag=(currtable==tblx.tableCode) pmkey=tblx.tableJavaCode+'ParamMap'/]
        [@doeditForUpdate tblx=tblx  sqlx=sqlx  dtkey=dtkey  rdkey=rdkey pmkey=pmkey ftype='1' blankflag='' currentitys=eVO.children![] currtableflag=currtableflag /]
        [/#if]
        [/#list]
        [#list mdx.orderEntitys["req"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0 && eVO.fieldType == "3"]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] dtkey1=eVO.fieldJavaCode?uncap_first+'List' dtkey=eVO.fieldJavaCode?uncap_first+'x' 
        rdkey=eVO.fieldJavaCode?uncap_first+'Record' pmkey=tblx.tableJavaCode+'ParamMap' /]
        List<${eVO.javaType}> ${dtkey1} = reqData.get${eVO.fieldJavaCode?cap_first}();
        if(${dtkey1} !=null  && ${dtkey1}.size()>0){
            for(${eVO.javaType} ${dtkey} : ${dtkey1}){
                [@doeditForUpdate tblx=tblx  sqlx=sqlx  dtkey=dtkey rdkey=rdkey pmkey=pmkey ftype='2' blankflag='        ' currentitys=eVO.children![] currtableflag=false /]
            }
        }
        [/#if]
        [/#list]
        
        [#assign eList = mdx.orderEntitys["res"]![] /]
        [#list eList as eVO]
        [#if eVO.useTableCode?trim?length>0]
        [#assign tblx = map_table[eVO.useTableCode]  sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] dtkey='resDTO' rdkey=tblx.tableJavaCode?uncap_first+'Record'
        pmkey=tblx.tableJavaCode+'ParamMap' /]
        [#if tblx.primaryEntity?size>0]
        [@doeditForSelect tblx=tblx sqlx=sqlx dtkey=dtkey rdkey=rdkey pmkey=pmkey existflag=true /]
        [/#if]
        [/#if]
        [/#list]
        
        [#elseif data_table?? && data_table?size>0]
        [#assign tblx=data_table[0] sqlx=tblx.sqlInterfacesMap['selectOne'] dtkey='reqData' rdkey=tblx.tableJavaCode+'Data'
         pmkey=tblx.tableJavaCode+'ParamMap' /]
        [#if tblx.primaryEntity?size>0]
        [#list tblx.primaryEntity as b]
        ${b.javaType} ${b.columnJavaCode} = ${dtkey+'.get'+b.columnJavaCode?cap_first+'()'};
        [/#list]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        ${tblx.tags['name_entity']} ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        if(${rdkey} == null){
            throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        [#assign tblx = data_table[0] sqlx=tblx.sqlInterfacesMap['updateMap'] dtkey='reqData' rdkey=tblx.tableJavaCode?uncap_first+'Record'
          pmkey=tblx.tableJavaCode+'ParamMap'/]
        [@doeditForUpdate tblx=tblx  sqlx=sqlx  dtkey=dtkey  rdkey=rdkey pmkey=pmkey ftype='1' blankflag='' currentitys=mdx.orderEntitys["req"]![] currtableflag=true /]
        
        [#assign tblx=data_table[0] sqlx=tblx.sqlInterfacesMap['selectOne'] dtkey='resDTO' rdkey=tblx.tableJavaCode?uncap_first+'Record'
           pmkey=tblx.tableJavaCode+'ParamMap' /]
        [@doeditForSelect tblx=tblx sqlx=sqlx dtkey=dtkey rdkey=rdkey pmkey=pmkey existflag=true /]
        [/#if]
        
        [/#if]
        return resDTO;
    }
    [#elseif mdx.methodOprType == 'dodelete' ]
    @Override
    public ${mdx.tags['name_res']} do${ServiceMethodName(data_main,mdx)}(${mdx.tags['name_req']} reqData) throws Exception{
        // TODO Auto-generated method stub
        ${mdx.tags['name_res']} resDTO = new ${mdx.tags['name_res']}();
        Date time = BaseManagerUtils.getSystemTime().getDate();
        
        [#if data_table?? && data_table?size>1]
        [#list mdx.orderEntitys["req"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0]
        [#assign tblx=map_table[eVO.useTableCode] sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] /]
        [#if tblx.primaryEntity?? && tblx.primaryEntity?size>0]
        [#if eVO.fieldType == "1"][#if currtable == ""][#assign currtable=tblx.tableCode /][/#if]
        [#list tblx.primaryEntity as b]
        ${b.javaType} ${b.columnJavaCode} = ${'reqData.get'+b.columnJavaCode?cap_first+'()'};
        [/#list]
        [#elseif eVO.fieldType == "2"][#if currtable == ""][#assign currtable=tblx.tableCode /][/#if]
        [#list tblx.primaryEntity as b]
        ${b.javaType} ${b.columnJavaCode} = ${'reqData.get'+eVO.fieldJavaCode?cap_first+'().get'+b.columnJavaCode?cap_first+'()'};
        [/#list]
        [/#if]
        [/#if]
        [/#if]
        [/#list]
        
        [#list mdx.orderEntitys["res"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0]
        [#assign tblx = map_table[eVO.useTableCode]  sqlx=tblx.sqlInterfacesMap[eVO.useTableSqlCode] rdkey=tblx.tableJavaCode+'Record'
          pmkey=tblx.tableJavaCode+'ParamMap' /]
        [#if tblx.primaryEntity?? && tblx.primaryEntity?size>0]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        ${tblx.tags['name_entity']} ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        if(${rdkey} == null){
            throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        [/#if]
        [/#if]
        [/#list]
        [#list mdx.orderEntitys["req"]![] as eVO]
        [#if eVO.useTableCode?trim?length>0]
        [#assign tblx2 = map_table[eVO.useTableCode]  sqlx2=tblx.sqlInterfacesMap[eVO.useTableSqlCode] pmkey=tblx.tableJavaCode+'ParamMap' /]
        [#if tblx2.tableCode==tblx.tableCode ]
        [#if tblx2.primaryEntity?size>0]
        int num=${tblx2.tags['lname_dao']}.${sqlx2.sqlId}(${pmkey});
        if(num!=1) {
           throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        
        [@copyResDTO tbl=tblx2 dtkey="reqData" rdkey="resDTO" /]
        [/#if]
        [#else]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx2 blankflag="" /]
        ${tblx2.tags['lname_dao']}.${sqlx2.sqlId}(${pmkey});
        [/#if]
        [/#if]
        [/#list]
        
        [#elseif data_table?? && data_table?size>0]
        [#assign tblx=data_table[0] sqlx=tblx.sqlInterfacesMap['selectOne'] rdkey=tblx.tableJavaCode+'Record' pmkey=tblx.tableJavaCode+'ParamMap' /]
        [#if tblx.primaryEntity?size>0]
        [#list tblx.primaryEntity as b]
        ${b.javaType} ${b.columnJavaCode} = ${dtkey+'.get'+b.columnJavaCode?cap_first+'()'};
        [/#list]
        [@copyTableParams eList=mdx.orderEntitys["req"]![] dtkey="reqData" pmkey=pmkey tblx=tblx blankflag="" /]
        ${tblx.tags['name_entity']} ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        if(${rdkey} == null){
            throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        ${tblx.tags['name_entity']} ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        [#assign tblx=data_table[0] sqlx=tblx.sqlInterfacesMap['deleteMap'] /]
        int num=${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        if(num!=1) {
           throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        
        [@copyResDTO tbl=tblx dtkey="reqData" rdkey="resDTO" /]
        [/#if]
        [/#if]
        return resDTO;
    }
    [#elseif mdx.methodOprType == 'getlist' ]
    [#elseif mdx.methodOprType == 'doexport' ]
    [#elseif mdx.methodOprType == 'doimport' ]
    [#else]
    @Override
    public ${mdx.tags['name_res']} do${ServiceMethodName(data_main,mdx)}(${mdx.tags['name_req']} reqData) throws Exception{
        // TODO Auto-generated method stub
        ${mdx.tags['name_res']} resDTO = new ${mdx.tags['name_res']}();
        Date time = BaseManagerUtils.getSystemTime().getDate();
        
        return resDTO;
    }
    [/#if]
[/#if]
[/#list]

[/#if]

[#-- 新增,实现了多表新增 --]
        [#macro doaddForInsert mdx tblx sqlx blankflag dtkey rdkey ftype currentitys]
        ${blankflag}${tblx.tags['name_entity']} ${rdkey} = new ${tblx.tags['name_entity']}();
        [@copyReqData eList=currentitys dtkey=dtkey rdkey=rdkey blankflag=blankflag /]
        ${blankflag}BaseManagerUtils.initCreateInfo(${rdkey}, time);
        [#if tblx.primaryEntity?size>0]
        [#list tblx.primaryEntity as b][#assign idtype=''/]
        [#if tblx.tableKeyType?length==0]
        [#elseif tblx.tableKeyImpl?length>0 || tblx.tableKeyType == "3"]
        [#assign idtype=tblx.tableKeyImpl /]
        [#elseif b.javaType?upper_case == 'STRING' || tblx.tableKeyType == "1"]
        [#assign idtype='IdUtil.simpleUUID()'/]
        [#elseif b.javaType?upper_case == 'LONG' || tblx.tableKeyType == "4"]
        [#assign idtype='BaseManagerUtils.getId()'/]
        [#elseif b.javaType?upper_case == 'STRING' || tblx.tableKeyType == "4"]
        [#assign idtype='BaseManagerUtils.getId().toString()'/]
        [#elseif b.javaType?upper_case != 'STRING' || tblx.tableKeyType == "2"]
        [#assign idtype='redisHashKey('+tblx.tableCode?replace("([a-z])([A-Z]+)","$1_$2","r")?upper_case+')'/] 
        [/#if]
        [#if idtype!=""]
        [#if ftype=="1"]
        ${blankflag}${b.columnJavaCode} = ${idtype};
        [#elseif ftype=="2"]
        ${blankflag}${b.javaType} ${b.columnJavaCode} = ${idtype};
        ${blankflag}${b.columnJavaCode+'Maps'}.put(${rdkey +'.get'+b.columnJavaCode?cap_first+'()'},${b.columnJavaCode});
        [/#if]
        ${blankflag}${rdkey+'.set'+b.columnJavaCode?cap_first}(${b.columnJavaCode});
        [/#if]
        [/#list]
        [/#if]
        [#if table_rels?? && table_rels?size>0 && table_rels[tblx.tableJavaCode]?? && table_rels[tblx.tableJavaCode]?size>0]
        [#list table_rels[tblx.tableJavaCode] as rb]
        [#if rb.PTableType=="1"]
        ${blankflag}${rdkey+'.set'+rb.CColumnJavaCode?cap_first}(${rb.PColumnJavaCode});//放入父表id
        [#elseif rb.PTableType=="2"]
        ${blankflag}${rdkey+'.set'+rb.CColumnJavaCode?cap_first}(${rb.PColumnJavaCode+'Maps'}.get(${rdkey+'.get'+rb.CColumnJavaCode?cap_first+'()'}));//放入父表id
        [/#if]
        [/#list]
        [/#if]
        ${blankflag}${tblx.tags['lname_dao']}.${sqlx.sqlId}(${rdkey});
        [#if tblx.primaryEntity?? && tblx.primaryEntity?size>0]
        [#list tblx.primaryEntity as b]
        [#if ftype=="1" && idtype==""]
        ${blankflag}${b.columnJavaCode} = ${rdkey +'.get'+b.columnJavaCode?cap_first+'()'};//自增的需拿到后面使用
        [#elseif ftype=="2" && idtype==""]
        ${blankflag}${b.columnJavaCode+'Maps'}.put(${dtkey +'.get'+b.columnJavaCode?cap_first+'()'},${rdkey +'.get'+b.columnJavaCode?cap_first+'()'});//自增的需拿到后面使用
        [/#if]
        [/#list]
        [/#if]
        [/#macro]
[#-- 更新类方法，实现的单表更新(多表不全) --]
        [#macro doeditForUpdate tblx sqlx dtkey rdkey pmkey ftype blankflag currentitys currtableflag]
        [#list tblx.primaryEntity as b]
        [#if ftype=="2"]
        ${blankflag}${b.javaType} ${b.columnJavaCode} = ${dtkey+'.get'+b.columnJavaCode?cap_first+'()'};
        ${blankflag}${b.columnJavaCode+'Maps'}.put(${b.columnJavaCode},${b.columnJavaCode});
        [/#if]
        [/#list]
        ${blankflag}${tblx.tags['name_entity']} ${rdkey} = new ${tblx.tags['name_entity']}();
        [@copyReqData eList=currentitys dtkey=dtkey rdkey=rdkey blankflag=blankflag /]
        ${blankflag}BaseManagerUtils.initUpdateInfo(${rdkey}, time);
        [@copyTableUpdParams currentitys=currentitys dtkey=dtkey pmkey=pmkey tblx=tblx ftype=ftype blankflag=blankflag existflag=currtableflag /]
        [#if currtableflag] 
        ${blankflag}int ${'updNum'+tblx.tableJavaCode?cap_first} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${rdkey},${pmkey});
        if(${'updNum'+tblx.tableJavaCode?cap_first}!=1) {
           throw new ServiceException(MessageUtils.message("data.is.expired"));
        }
        [#else]
        ${blankflag}${tblx.tags['lname_dao']}.${sqlx.sqlId}(${rdkey},${pmkey});
        [/#if]
        [/#macro]
[#-- 根据主键查询主表单条基础记录返回 --]
        [#macro doeditForSelect tblx sqlx dtkey rdkey pmkey existflag]
        [#if !existflag]${tblx.tags['name_entityVo']} [/#if]${pmkey} = new ${tblx.tags['name_entityVo']}();
        [#list tblx.primaryEntity as b]
        ${pmkey}.set${b.columnJavaCode?cap_first}(${b.columnJavaCode});
        [/#list]
        ${rdkey} = ${tblx.tags['lname_dao']}.${sqlx.sqlId}(${pmkey});
        BeanUtils.copyProperties(${rdkey}, ${dtkey});
        [/#macro]
        
[#-- 生成set赋值 --]
        [#macro copyReqData eList dtkey rdkey blankflag]
        [#list eList as eVO]
        [#if checkTypeFunc(eVO.fieldUseType,["1","3","4"]) && checkTypeFunc(eVO.fieldType,["1"])]
        ${blankflag}${rdkey+".set"+eVO.fieldJavaCode?cap_first}(${dtkey+'.get'+eVO.fieldJavaCode?cap_first+'()'});
        [/#if]
        [/#list]
        [/#macro]
[#-- 更新表条件赋值 --]
        [#macro copyTableUpdParams currentitys dtkey pmkey tblx ftype blankflag existflag]
        ${blankflag}[#if !existflag]${tblx.tags['name_entityVo']} [/#if]${pmkey} = new ${tblx.tags['name_entityVo']}();
        [#if ftype=="1"]
        [#list tblx.primaryEntity as b]
        ${blankflag}${pmkey}.set${b.columnJavaCode?cap_first}(${dtkey+'.get'+b.columnJavaCode?cap_first+'()'});
        [/#list]
        [/#if]
        [#list currentitys as b]
        [#if checkTypeFunc(b.fieldJavaCode,versionUpds) ]
        ${blankflag}${pmkey}.set${b.fieldJavaCode?cap_first}(${dtkey+'.get'+b.fieldJavaCode?cap_first+'()'});
        [/#if]
        [/#list]
        [/#macro]
[#-- 查询表条件赋值 --]
        [#macro copyTableParams eList dtkey pmkey tblx blankflag]
        ${tblx.tags['name_entityVo']} ${pmkey} = new ${tblx.tags['name_entityVo']}();
        [#list eList as eVO]
        [#if checkTypeFunc(eVO.fieldUseType,["1","3","4"]) ]
        ${blankflag}${pmkey}.set${eVO.fieldJavaCode?cap_first}(${dtkey+'.get'+eVO.fieldJavaCode?cap_first+'()'});
        [/#if]
        [/#list]
        [/#macro]
[#-- 返回关键字段赋值 --]
        [#macro copyResDTO tbl dtkey rdkey]
        [#list tblx.ownEntity as b]
        [#if checkTypeFunc(b.primarykeyFlag,["1"])]
        ${rdkey}.set${b.columnJavaCode?cap_first}(${b.columnJavaCode});
        [#elseif checkTypeFunc(b.columnJavaCode,["updateBy"])]
        ${rdkey}.setUpdateBy(SecurityUtils.getUserId().toString());
        [#elseif checkTypeFunc(b.columnJavaCode,["updateByName"])]
        ${rdkey}.setUpdateByName(SecurityUtils.getNickname());
        [#elseif checkTypeFunc(b.columnJavaCode,["updateTime"])]
        ${rdkey}.setUpdateTime(time);
        [/#if]
        [/#list]
        [/#macro]

}